package testes;

import static org.junit.Assert.*;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.quasar.copaPaises.businessLayer.*;

public class CalendarDateTest {

	@BeforeClass
	public static void setUpBeforeClass() throws Exception {
	}

	@AfterClass
	public static void tearDownAfterClass() throws Exception {
	}

	@Before
	public void setUp() throws Exception {
		CalendarDate.allInstances.clear();
		Campeonato.allInstances.clear();
		Cartao.allInstances.clear();
		Cidade.allInstances.clear();
		Clube.allInstances.clear();
		Continente.allInstances.clear();
		Equipa.allInstances.clear();
		Estadio.allInstances.clear();
		Golo.allInstances.clear();
		Grupo.allInstances.clear();
		Jogador.allInstances.clear();
		Jogo.allInstances.clear();
		Membro.allInstances.clear();
		Pais.allInstances.clear();
		Participacao.allInstances.clear();
		Participante.allInstances().clear();
		Treinador.allInstances.clear();
	}

	@After
	public void tearDown() throws Exception {
		CalendarDate.allInstances.clear();
		Campeonato.allInstances.clear();
		Cartao.allInstances.clear();
		Cidade.allInstances.clear();
		Clube.allInstances.clear();
		Continente.allInstances.clear();
		Equipa.allInstances.clear();
		Estadio.allInstances.clear();
		Golo.allInstances.clear();
		Grupo.allInstances.clear();
		Jogador.allInstances.clear();
		Jogo.allInstances.clear();
		Membro.allInstances.clear();
		Pais.allInstances.clear();
		Participacao.allInstances.clear();
		Participante.allInstances().clear();
		Treinador.allInstances.clear();
	}

	@Test
	public final void testCalendarDate() {
		CalendarDate data = new CalendarDate();
		assertNotNull(data);
	}

	@Test
	public final void testCalendarDateIntIntInt() {
		int dia = 12;
		int mes = 4;
		int ano = 2012;
		CalendarDate data = new CalendarDate(dia, mes, ano);
		assertNotNull(data);
		assertEquals(data.day(), dia);
		assertEquals(data.month(), mes);
		assertEquals(data.year(), ano);
	}

	@Test
	public final void testDay() {
		int dia = 12;
		int mes = 4;
		int ano = 2012;
		CalendarDate data = new CalendarDate(dia, mes, ano);
		assertEquals(data.day(), dia);
	}

	@Test
	public final void testSetDay() {
		int dia = 12;
		CalendarDate data = new CalendarDate();
		data.setDay(dia);
		assertEquals(data.day(), dia);
	}

	@Test
	public final void testMonth() {
		int dia = 12;
		int mes = 4;
		int ano = 2012;
		CalendarDate data = new CalendarDate(dia, mes, ano);
		assertEquals(data.month(), mes);
	}

	@Test
	public final void testSetMonth() {
		int mes = 4;
		CalendarDate data = new CalendarDate();
		data.setMonth(mes);
		assertEquals(data.month(), mes);
	}

	@Test
	public final void testYear() {
		int dia = 12;
		int mes = 4;
		int ano = 2012;
		CalendarDate data = new CalendarDate(dia, mes, ano);
		assertEquals(data.year(), ano);
	}

	@Test
	public final void testSetYear() {
		int ano = 2012;
		CalendarDate data = new CalendarDate();
		data.setYear(ano);
		assertEquals(data.year(), ano);
	}

	@Test
	public final void testInitS() {
		String dataString = "2012-04-12";
		CalendarDate data = new CalendarDate();

		assertEquals(data.day(), 0);
		assertEquals(data.month(), 0);
		assertEquals(data.year(), 0);

		data.initS(dataString);

		assertEquals(data.day(), 12);
		assertEquals(data.month(), 4);
		assertEquals(data.year(), 2012);

	}

	@Test
	public final void testIsAfter() {
		CalendarDate dataTeste = new CalendarDate(10, 5, 2012);
		CalendarDate d1 = new CalendarDate(10, 5, 2010);
		CalendarDate d2 = new CalendarDate(10, 5, 2015);
		CalendarDate d3 = new CalendarDate(10, 3, 2012);
		CalendarDate d4 = new CalendarDate(10, 6, 2012);
		CalendarDate d5 = new CalendarDate(5, 5, 2012);
		CalendarDate d6 = new CalendarDate(14, 5, 2012);
		CalendarDate d7 = new CalendarDate(10, 5, 2012);
		assertTrue(dataTeste.isAfter(d1));
		assertFalse(dataTeste.isAfter(d2));
		assertTrue(dataTeste.isAfter(d3));
		assertFalse(dataTeste.isAfter(d4));
		assertTrue(dataTeste.isAfter(d5));
		assertFalse(dataTeste.isAfter(d6));
		assertFalse(dataTeste.isAfter(d7));

	}

	@Test
	public final void testIsBefore() {
		CalendarDate dataTeste = new CalendarDate(10, 5, 2012);
		CalendarDate d1 = new CalendarDate(10, 5, 2010);
		CalendarDate d2 = new CalendarDate(10, 5, 2015);
		CalendarDate d3 = new CalendarDate(10, 3, 2012);
		CalendarDate d4 = new CalendarDate(10, 6, 2012);
		CalendarDate d5 = new CalendarDate(5, 5, 2012);
		CalendarDate d6 = new CalendarDate(14, 5, 2012);
		CalendarDate d7 = new CalendarDate(10, 5, 2012);
		assertFalse(dataTeste.isBefore(d1));
		assertTrue(dataTeste.isBefore(d2));
		assertFalse(dataTeste.isBefore(d3));
		assertTrue(dataTeste.isBefore(d4));
		assertFalse(dataTeste.isBefore(d5));
		assertTrue(dataTeste.isBefore(d6));
		assertFalse(dataTeste.isBefore(d7));
	}

	@Test
	public final void testIsDivisible() {
		CalendarDate data = new CalendarDate();
		assertTrue(data.isDivisible(10, 2));
		assertFalse(data.isDivisible(10, 3));
	}

	@Test
	public final void testIsEqual() {
		int dia = 10;
		int mes = 3;
		int ano = 2012;
		CalendarDate data = new CalendarDate(dia, mes, ano);
		CalendarDate data2 = new CalendarDate(dia, mes, ano);
		CalendarDate data3 = new CalendarDate(dia, mes, 1998);
		CalendarDate data4 = new CalendarDate(dia, 4, ano);
		CalendarDate data5 = new CalendarDate(12, mes, ano);
		assertTrue(data.isEqual(data2));
		assertFalse(data.isEqual(data3));
		assertFalse(data.isEqual(data4));
		assertFalse(data.isEqual(data5));
	}

	@Test
	public final void testIsLeap() {
		CalendarDate data1 = new CalendarDate(12, 03, 2012);
		CalendarDate data2 = new CalendarDate(12, 03, 2011);
		CalendarDate data3 = new CalendarDate(12, 03, 800);
		assertTrue(data1.isLeap());
		assertFalse(data2.isLeap());
		assertTrue(data3.isLeap());
	}

	@Test
	public final void testStringToDate() {
		String dataString = "2012-12-04";
		CalendarDate data = new CalendarDate();
		data = data.stringToDate(dataString);
		assertEquals(data.day(), 4);
		assertEquals(data.month(), 12);
		assertEquals(data.year(), 2012);

	}

	@Test
	public final void testYearsSince() {
		CalendarDate data1 = new CalendarDate(12, 10, 1986);
		CalendarDate data2 = new CalendarDate(12, 12, 2000);
		CalendarDate data3 = new CalendarDate(14, 8, 2000);
		CalendarDate data4 = new CalendarDate(20, 10, 2000);
		CalendarDate data5 = new CalendarDate(12, 10, 2000);
		CalendarDate data6 = new CalendarDate(8, 10, 2000);

		assertEquals(data1.yearsSince(data2), 13);
		assertEquals(data1.yearsSince(data3), 14);
		assertEquals(data1.yearsSince(data4), 13);
		assertEquals(data1.yearsSince(data5), 14);
		assertEquals(data1.yearsSince(data6), 14);

	}

	@Test
	public final void testToString() {
		CalendarDate data = new CalendarDate();
		String toString = "CalendarDate [day=0, month=0, year=0]\n";
		assertEquals(data.toString(), toString);

	}

}
